<div class="layuimini-main">

    <div class="layui-form layuimini-form" lay-filter="updateSubmit">
        <input type="hidden" name="id" id="id">
        <input type="hidden" name="deptId" id="deptId">
        <input type="hidden" name="jobTitle2" id="jobTitle2">
        <div class="layui-form-item">
            <label class="layui-form-label required">用户名</label>
            <div class="layui-input-block">
                <input type="text" name="username" lay-verify="required" lay-reqtext="用户名不能为空" placeholder="请输入用户名" value="" class="layui-input">
                <tip>填写自己管理账号的名称。</tip>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label required">密码</label>
            <div class="layui-input-block">
                <input type="password" name="password" lay-verify="required" lay-reqtext="密码不为空" placeholder="123456" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">角色</label>
            <div class="layui-input-block">
                <select name="roleName" lay-verify="required" lay-search="">
                    <option value="">请选择</option>
                    <option value="1">管理员</option>
                    <option value="0">医生</option>
                </select>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">职称</label>
            <div class="layui-input-block">
                <select name="jobTitle" lay-verify="required" id="jobTitle" lay-filter="bojTitle"  lay-search="">

                </select>
            </div>
        </div>

        <!--部门科室测试-->
        <div class="layui-form-item">
            <label  class="layui-form-label">所在部门</label>
            <div class="layui-input-block">
                <input type="text" id="tree" name="deptId" lay-filter="tree" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label required">性别</label>
            <div class="layui-input-block">
                <input type="radio" name="sex" value="男" title="男" checked="">
                <input type="radio" name="sex" value="女" title="女">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label required">手机</label>
            <div class="layui-input-block">
                <input type="text" name="tel" lay-verify="required" lay-reqtext="手机不能为空" placeholder="请输入手机" value="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">邮箱</label>
            <div class="layui-input-block">
                <input type="email" name="email" placeholder="请输入邮箱" value="" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">个人介绍</label>
            <div class="layui-input-block">
                <textarea name="info" class="layui-textarea" placeholder="请输入备注信息"></textarea>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn layui-btn-normal" lay-submit lay-filter="updateSubmit">确认保存</button>
            </div>
        </div>
    </div>
</div>
<script>
    layui.use(['treeSelect','form', 'table','axios'], function () {
        var form = layui.form,
            layer = layui.layer,
            table = layui.table,
            $ = layui.$;
        var treeSelect= layui.treeSelect;
        var axios = layui.axios;

        treeSelect.render({
            // 选择器
            elem: '#tree',
            // 数据
            data: 'http://localhost:9999/dept/queryDeptTree',
            // 异步加载方式：get/post，默认get
            type: 'get',
            // 占位符
            placeholder: '修改默认提示信息',
            // 是否开启搜索功能：true/false，默认false
            search: true,
            // 点击回调
            click: function(d){
                console.log(d);
                $("#tree").val(d.current.id)
            },
            // 加载完成后的回调函数
            success: function (d) {
                var values=$("#deptId").val();
                treeSelect.checkNode('tree',values);
            }
        });


        //渲染 职称信息
        axios.post('titleInfo/titleAll',{}).then(function(res){
            let option =' <option value="">请选择</option>';
            res.data.forEach(item=>{
                if(item.name==$("#jobTitle2").val()){
                    option =`<option value="${item.name}" selected>${item.name}</option>`
                }else{
                     option =`<option value="${item.name}">${item.name}</option>`
                }

                $('#jobTitle').append(option);
            })
            form.render();
        });

        /**
         * 初始化表单，要加上，不然刷新部分组件可能会不加载
         */
        form.render();

        // 当前弹出层，防止ID被覆盖
        var parentIndex = layer.index;
        //监听提交
        form.on('submit(updateSubmit)', function (data) {
            var data=data.field;
            axios.post('user/update',data).then(function(response){
                debugger
                if(response.data.code==200){
                    layer.msg(response.data.msg);
                    //重新加载表格
                    window.reload()
                }
                //关闭弹出页面
                layer.close(parentIndex);
            }).catch(err=> {
                    console.log(err);
                }
            );


            return false;
        });

    });
</script>